0

I am working on developing a Parser , I would like to check Yacc Syntax using Regular Expression. But It seems that it doesn't work out

       // Yacc-like grammar specifications

//        Ligne ::= Expr '\n' {printf("%d \n" , $1)}
//        Expr : Exp '+' Terme {$$ = $1 + $3; } | Terme ;
//        Terme : Terme '*' Facteur  {$$ = $1 * $3; } | Facteur ;  
//        Facteur : '(' Expr ')'  {$$ = $2; } | Chiffre ;  


String YaccProdS = @"($$)+ [=] [$]+[0-9][^']([$]+[0-9])*";
Check = Regex.Match(Text,YaccProdS);

1 Answer 1

0

If you are just looking to get what is inside of the {} the following will get you that, it will also group the $id and the operator.

String YaccProdS = @"(\$+)\s+=\s+(\$+\d+)(\s*([*+\/])\s*(\$+[0-9]+))?"; 

Always remember to escape your special characters, like $.

8
  • It works for the first one , but it doesn't work for this {$$ = $2; }
    – ImnotaGeek
    Commented Jun 11, 2013 at 20:23
  • Since the action of a Yacc rule can be arbitrary C syntax, you have to tokenize C.
    – Kaz
    Commented Jun 11, 2013 at 20:25
  • I modified the answer to fit those requirements Commented Jun 11, 2013 at 20:25
  • What if the rule has this? { $$ = make_node('}', $1, $2); }.
    – Kaz
    Commented Jun 11, 2013 at 20:26
  • Where did that input come from? Maybe you should edit your question to have all the cases you want to match Commented Jun 11, 2013 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.