|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Diggins.Jigsaw
{
class ArithmeticGrammar : SharedGrammar
{
new public static Rule Integer = Node(SharedGrammar.Integer);
new public static Rule Float = Node(SharedGrammar.Float);
public static Rule RecExpr = Recursive(() => Expression);
public static Rule ParanExpr = Node(CharToken('(') + RecExpr + WS + CharToken(')'));
public static Rule Number = (Integer | Float) + WS;
public static Rule PrefixOp = Node(MatchStringSet("! - ~"));
public static Rule PrefixExpr = Node(PrefixOp + Recursive(() => SimpleExpr));
public static Rule SimpleExpr = PrefixExpr | Number | ParanExpr;
public static Rule BinaryOp = Node(MatchStringSet("<= >= == != << >> && || < > & | + - * % / ^"));
public static Rule Expression = Node(SimpleExpr + ZeroOrMore(BinaryOp + WS + SimpleExpr));
static ArithmeticGrammar() { InitGrammar(typeof(ArithmeticGrammar)); }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.