1

I am writing a parser for the PowerShell language, using the grammar described here: http://www.microsoft.com/en-us/download/details.aspx?id=9706.

I used Irony, and the Irony Grammar Explorer is reporting some shift/reduce and reduce/reduce errors. This one has me stumped, because I'm not sure what it's telling me.

State S79 (Inadequate)
  Shift-reduce conflicts on inputs: [ , + dash ++ dashdash
  Shift items:
    cast_expression -> type_literal ·unary_expression 
    unary_expression -> ·primary_expression 
    primary_expression -> ·value 
    value -> ·parenthesized_expression 
    parenthesized_expression -> ·( pipeline ) 
    value -> ·sub_expression 
    sub_expression -> ·$( statement_list_opt ) 
    value -> ·array_expression 
    array_expression -> ·@( statement_list_opt ) 
    value -> ·script_block_expression 
    script_block_expression -> ·{ script_block } 
    value -> ·hash_literal_expression 
    hash_literal_expression -> ·@{ hash_literal_body_opt } 
    value -> ·literal 
    literal -> ·integer_literal 
    integer_literal -> ·decimal_integer_literal 
    integer_literal -> ·hexadecimal_integer_literal 
    literal -> ·real_literal 
    literal -> ·string_literal 
    string_literal -> ·expandable_string_literal 
    string_literal -> ·verbatim_string_literal 
    value -> ·type_literal 
    type_literal -> ·[ type_spec ] 
    value -> ·variable 
    primary_expression -> ·member_access 
    member_access -> ·primary_expression Unnamed6 member_name 
    primary_expression -> ·element_access 
    element_access -> ·primary_expression [ expression ] 
    primary_expression -> ·post_increment_expression 
    post_increment_expression -> ·primary_expression ++ 
    primary_expression -> ·post_decrement_expression 
    post_decrement_expression -> ·primary_expression dashdash 
    unary_expression -> ·expression_with_unary_operator 
    expression_with_unary_operator -> ·, unary_expression 
    expression_with_unary_operator -> ·-not unary_expression 
    expression_with_unary_operator -> ·! unary_expression 
    expression_with_unary_operator -> ·-bnot unary_expression 
    expression_with_unary_operator -> ·+ unary_expression 
    expression_with_unary_operator -> ·dash unary_expression 
    expression_with_unary_operator -> ·pre_increment_expression 
    pre_increment_expression -> ·++ unary_expression 
    expression_with_unary_operator -> ·pre_decrement_expression 
    pre_decrement_expression -> ·dashdash unary_expression 
    expression_with_unary_operator -> ·cast_expression 
    cast_expression -> ·type_literal unary_expression 
    expression_with_unary_operator -> ·-split unary_expression 
    expression_with_unary_operator -> ·-join unary_expression 
  Reduce items:
    value -> type_literal · [assignment_operator . :: [ ++ dashdash , .. format_operator * / % + dash as ccontains ceq cge cgt cle clike clt cmatch cne cnotcontains cnotlike cnotmatch contains creplace csplit eq ge gt icontains ieq ige igt ile ilike ilt imatch ine inotcontains inotlike inotmatch ireplace is isnot isplit join le like lt match ne notcontains notlike notmatch replace split -band -bor -bxor -and -or -xor 2>&1 1>&2 file_redirection_operator | ; new_line_character EOF } ) = ]]
  Transitions: unary_expression->S187, primary_expression->S158, value->S60, parenthesized_expression->S61, (->S62, sub_expression->S63, $(->S64, array_expression->S65, @(->S66, script_block_expression->S67, {->S68, hash_literal_expression->S69, @{->S70, literal->S71, integer_literal->S72, decimal_integer_literal->S73, hexadecimal_integer_literal->S74, real_literal->S75, string_literal->S76, expandable_string_literal->S77, verbatim_string_literal->S78, type_literal->S79, [->S80, variable->S81, member_access->S82, element_access->S83, post_increment_expression->S84, post_decrement_expression->S85, expression_with_unary_operator->S97, ,->S98, -not->S99, !->S100, -bnot->S101, +->S102, dash->S103, pre_increment_expression->S104, ++->S105, pre_decrement_expression->S106, dashdash->S107, cast_expression->S108, -split->S109, -join->S110

If you want to look at yourself, the code is here: https://github.com/Pash-Project/Pash/tree/method-invocation/Source/Pash.System.Management

Edit: I think the input this gets confused on is:

[int] +7

Is this addition or casting?

Jay Bazuzi
  • 45,157
  • 15
  • 111
  • 168
  • This is cross-posted from http://irony.codeplex.com/discussions/437270, but I thought maybe SO is a better place for it. – Jay Bazuzi Mar 20 '13 at 17:06
  • The github links are busted. Repo's gone? – Charles Mar 21 '13 at 01:30
  • @Charles: Thanks for catching that - I just moved the repo & forgot to update my question. Fixed. Also: http://stackoverflow.com/questions/15538300/when-i-move-a-repo-on-github-how-can-i-forward-the-old-location – Jay Bazuzi Mar 21 '13 at 02:14
  • I agree with Roman; you should be looking at reworking your grammar definition to parse with the Parser, and scan with the Scanner, by reducing your plethora of terminals. – Pieter Geerkens Mar 22 '13 at 10:56
  • Thanks for the advice, Pieter. Since the grammar is published by Microsoft, I was hoping to use it as-is, but I guess I have some work to do. – Jay Bazuzi Mar 22 '13 at 11:19
  • @PieterGeerkens: Just to clarify, in what way do you see me not parsing with the parser? – Jay Bazuzi Mar 22 '13 at 11:53
  • @Jay: You are reading my comment backwards; You seem to have the Scanner doing too much, and the Parser too little. – Pieter Geerkens Mar 22 '13 at 15:53
  • @PieterGeerkens: Ahh, I see. Can you give me an example of a Terminal you think should be a NonTerminal? Would you be up for meeting me in a chat room? – Jay Bazuzi Mar 22 '13 at 20:46

0 Answers0