Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Simple Embedded Expression Evaluation

Simple Embedded Expression Evaluation

2012-11-25 by Chuck Hackett

I am looking for a simple expression evaluation routine for use in an AVR
embedded system.  My needs are simple:

- Binary logical operators: logical AND (&) and OR(|)
- Unary operator NOT(!)
- Parentheses
- Known (system) variables (T1, S1, etc.)

Expressions such as:
(T1 | S1) & (T2 | S2)

All values are logical (i.e.: True/False).

Later I might add logical functions but that's down the road.

Anyone have a favorite?
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Re: [AVR-Chat] Simple Embedded Expression Evaluation

2012-11-25 by Jim Wagner

Is this an ASCII input or are the variables just pin states? Is the expression variable from one time to the next (that is, does the machine have to parse the expression) or is the expression set at compile time?

Jim Wagner

On Nov 25, 2012, at 2:08 PM, Chuck Hackett wrote:

> I am looking for a simple expression evaluation routine for use in an AVR
> embedded system. My needs are simple:
> 
> - Binary logical operators: logical AND (&) and OR(|)
> - Unary operator NOT(!)
> - Parentheses
> - Known (system) variables (T1, S1, etc.)
> 
> Expressions such as:
> (T1 | S1) & (T2 | S2)
> 
> All values are logical (i.e.: True/False).
> 
> Later I might add logical functions but that's down the road.
> 
> Anyone have a favorite?
>  
> Cheers,
> 
> Chuck Hackett
> "Good judgment comes from experience, experience comes from bad judgment"
> 7.5" gauge Union Pacific Northern (4-8-4) 844
> http://www.whitetrout.net/Chuck
> 
> 



[Non-text portions of this message have been removed]

Re: Simple Embedded Expression Evaluation

2012-11-25 by Don Kinzer

--- In AVR-Chat@yahoogroups.com, "Chuck Hackett" <egroupscdh@...> wrote:
> I am looking for a simple expression evaluation routine [...]
An operator precedence parser is a pretty simple mechanism and easy to implement.  With a web search you may be able to find source code (in C) for such a parser that can be modified to fit your needs.

Don Kinzer
ZBasic Microcontrollers
http://www.zbasic.net

RE: [AVR-Chat] Simple Embedded Expression Evaluation

2012-11-26 by Chuck Hackett

> From: Jim Wagner
> 
> Is this an ASCII input or are the variables just pin states? Is the
expression
> variable from one time to the next (that is, does the machine have to
parse
> the expression) or is the expression set at compile time?

Expression is in ASCII and is evaluated at run time.

The "known variables" I referred to are values known at run time - they are,
in fact, the "occupied" / "unoccupied" state of tracks in a 7.5" railroad -
this logic is part of the signal system logic.

So: "(T1 & T2) | T3" evaluates to true if "Track 1 AND Track 2 are occupied,
OR Track 3 is occupied"

The expression is part of the configuration data loaded into the control
node at the time it is configured by the user.
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Re: [AVR-Chat] Simple Embedded Expression Evaluation

2012-11-26 by Jim Wagner

Chuck

So, are the variables internally determined (for example, from sensors) while the expression is entered by the user such that the symbols (T1, and so forth) are just references to the internal variables?

Jim Wagner
Oregon Research Electronics

On Nov 25, 2012, at 4:23 PM, Chuck Hackett wrote:

> > From: Jim Wagner
> > 
> > Is this an ASCII input or are the variables just pin states? Is the
> expression
> > variable from one time to the next (that is, does the machine have to
> parse
> > the expression) or is the expression set at compile time?
> 
> Expression is in ASCII and is evaluated at run time.
> 
> The "known variables" I referred to are values known at run time - they are,
> in fact, the "occupied" / "unoccupied" state of tracks in a 7.5" railroad -
> this logic is part of the signal system logic.
> 
> So: "(T1 & T2) | T3" evaluates to true if "Track 1 AND Track 2 are occupied,
> OR Track 3 is occupied"
> 
> The expression is part of the configuration data loaded into the control
> node at the time it is configured by the user.
>  
> Cheers,
> 
> Chuck Hackett
> "Good judgment comes from experience, experience comes from bad judgment"
> 7.5" gauge Union Pacific Northern (4-8-4) 844
> http://www.whitetrout.net/Chuck
> 
> 



[Non-text portions of this message have been removed]

Re: [AVR-Chat] Simple Embedded Expression Evaluation

2012-11-26 by Mauro Zanin

Our sql server engine has this native capability ambedded. It can evaluate stored or realtime using stored or realtime parameters. It runs on a windows server.

Ciao
Mauro Zanin
Logic Data
Show quoted textHide quoted text
  ----- Original Message ----- 
  From: Chuck Hackett 
  To: AVR-Chat 
  Sent: Sunday, November 25, 2012 11:08 PM
  Subject: [AVR-Chat] Simple Embedded Expression Evaluation


    
  I am looking for a simple expression evaluation routine for use in an AVR
  embedded system. My needs are simple:

  - Binary logical operators: logical AND (&) and OR(|)
  - Unary operator NOT(!)
  - Parentheses
  - Known (system) variables (T1, S1, etc.)

  Expressions such as:
  (T1 | S1) & (T2 | S2)

  All values are logical (i.e.: True/False).

  Later I might add logical functions but that's down the road.

  Anyone have a favorite?
   
  Cheers,

  Chuck Hackett
  "Good judgment comes from experience, experience comes from bad judgment"
  7.5" gauge Union Pacific Northern (4-8-4) 844
  http://www.whitetrout.net/Chuck



  

[Non-text portions of this message have been removed]

RE: [AVR-Chat] Simple Embedded Expression Evaluation

2012-11-26 by Chuck Hackett

> From: Jim Wagner
> 
> So, are the variables internally determined (for example, from sensors)
while
> the expression is entered by the user such that the symbols (T1, and so
> forth) are just references to the internal variables?

Exactly Jim, currently the configuration allows specifying several variables
(i.e.: "if this track is occupied or that track is occupied set this signal
to red") but I want to make it more flexible for the user by allowing them
to specify an arbitrary logical expression involving an arbitrary number of
inputs (typically track occupancy sensors but expandable to contact
closures, etc.).

Later I will extend the expression processing to support references to
built-in functions such as:

(T1 & VO(T2,1.2))

Where "VO(I,v)" returns true if the value of sensor "I" is greater than
value "v".

Once this mechanism is in place it opens up a lot of flexibility with
minimum code investment on my part and, at the user level, makes it more
"extensible".  This allows the railroad signal controller to do things that
I, the designer, didn't anticipate which has always been a goal of mine in
my professional carrier as a software developer.  Now, using
microcontrollers, I have to accomplish it in a MUCH smaller container :-)
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

RE: [AVR-Chat] Re: Simple Embedded Expression Evaluation

2012-11-26 by Chuck Hackett

> From: Don Kinzer
>
> --- In AVR-Chat@yahoogroups.com, "Chuck Hackett" <egroupscdh@...>
> wrote:
> > I am looking for a simple expression evaluation routine [...]
> An operator precedence parser is a pretty simple mechanism and easy to
> implement.  With a web search you may be able to find source code (in C)
> for such a parser that can be modified to fit your needs.

Hi Don, yes, I have found a couple "starting points" but I thought I'd ask
the AVR community if someone had one that already worked well in the
embedded environment.

I knew that resurrecting my (minimal) YAK/LEX skills might be overkill for
this :-)
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.